//
//  MYBaseTableViewController.swift
//  swift2.0项目开始
//
//  Created by 龚昕炜 on 16/7/28.
//  Copyright © 2016年 龚昕炜. All rights reserved.
//

import UIKit

class MYBaseTableViewController: UITableViewController, MYVisitorDelegate {
    
    let visitor = MYVisitorView()
    
    var token: String = MYLoginViewModel.shareInstance.access_token ?? ""
    
    /** 拦截加载视图的方法，修改它 */
    override func loadView() {

        /** 已登录显示tableView */
        if MYLoginViewModel.shareInstance.isLogin {
            super.loadView()
        } else {
            /** 未登录显示访客视图 */
            view = visitor
        
            visitor.delegate = self
            
            setUpNav()
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
    
    // MARK: 设置nav
    private func setUpNav() {
        
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: .Plain, target: self, action: "didRegisterMethod")
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登录", style: .Plain, target: self, action: "didLoginMethod")
    }
    
//    override func viewDidAppear(animated: Bool) {
//        super.viewDidAppear(true)
//        
//    }
    
    /** 实现代理方法 */
    func didRegisterMethod() {
        
        let loginVc = MYOAuthViewController()
        
        let nav = UINavigationController(rootViewController: loginVc)
        
        self.presentViewController(nav, animated: true, completion: nil)
    }
    
    func didLoginMethod() {
        
    }

}